﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SkypeKit;
using System.IO;

namespace ISIM
{
    public partial class SkypeAccountPreferences : Form
    {
        SktAccount account;
        public SkypeAccountPreferences(SktAccount account)
        {
            InitializeComponent();
            this.account = account;

            fullNameLabel.Text = Global.LangManager.Translate("fullName");
            moodLabel.Text = Global.LangManager.Translate("mood");
            changeAvatar.Text = Global.LangManager.Translate("change");
            saveBT.Text = Global.LangManager.Translate("save");

            avatar.Image = Image.FromStream(new MemoryStream(account.P_AVATAR_IMAGE));
            fullName.Text = account.P_FULLNAME;
            email.Text = account.P_EMAILS;
            webSite.Text = account.P_HOMEPAGE;
            mood.Text = account.P_MOOD_TEXT;
        }

        private void saveBT_Click(object sender, EventArgs e)
        {
            MemoryStream ms = new MemoryStream();
            avatar.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            account.SetBinProperty((int)SktAccount.PropKeys.P_AVATAR_IMAGE, ms.ToArray());
            account.SetStrProperty((int)SktAccount.PropKeys.P_FULLNAME, fullName.Text);
            account.SetStrProperty((int)SktAccount.PropKeys.P_EMAILS, email.Text);
            account.SetStrProperty((int)SktAccount.PropKeys.P_HOMEPAGE, webSite.Text);
            account.SetStrProperty((int)SktAccount.PropKeys.P_MOOD_TEXT, mood.Text);

            this.Close();
        }

        private void changeAvatar_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            fd.Filter = "All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff";
            fd.Title = "Choose new avatar image";
            fd.Multiselect = false;
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                avatar.Image = Image.FromFile(fd.FileName);
            }
        }


    }
}
